﻿<UserControl x:Class="QuailDashboard.View.Controls.TestRunLogsControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:QuailControls="clr-namespace:QuailDashboard.View.Controls" 
    xmlns:c1grid="clr-namespace:C1.Silverlight.DataGrid;assembly=C1.Silverlight.DataGrid" 
    xmlns:Converters="clr-namespace:QuailDashboard.View.Converters" 
    xmlns:controls="clr-namespace:System.Windows;assembly=System.Windows.Controls" 
    xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" >
    <UserControl.Resources>
        <Converters:StatusConverter x:Key="StatusConverter" />
        <Converters:ExpandLeftConverter x:Key="ExpandLeftConverter" />
        <DataTemplate x:Key="myHierarchicalTemplate" >
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="18" />
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Image
                    Grid.Row="0"
                    Grid.Column="0"
                    Width="16"
                    Height="16"
                    Source="{Binding TaskStatusId, Converter={StaticResource StatusConverter}}" />
                <TextBlock
                    Grid.Row="0"
                    Grid.Column="1"
                    Text="{Binding TaskName}" />
                <TextBlock
                    Grid.Row="0"
                    Grid.Column="2"
                    Text="{Binding Duration}"
                    FontStyle="Italic"
                    Margin="5, 0, 5, 0" />
            </Grid>
        </DataTemplate>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Loaded="OnLayoutRootLoaded">
        <ScrollViewer x:Name="ContentScrollViewer" Style="{StaticResource PageScrollViewerInContentStyle}" SizeChanged="OnLayoutRootSizedChanged">

            <Grid VerticalAlignment="Top">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <!--The first two columns are currently hidden/unused reserved for future use to display the falure log entries -->
                    <ColumnDefinition x:Name="ColumnLogs" MinWidth="0" MaxWidth="600" Width="0" />
                    <ColumnDefinition x:Name="ColumnLogSplitter" Width="0" /> 
                    <ColumnDefinition MinWidth="150" MaxWidth="400" Width="300" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <Border
                        x:Name="SectionAllLogEntries" 
                        Grid.Row="0" 
                        Grid.Column="0" 
                        Style="{StaticResource DetailBorder}">
                    <Grid >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="25" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left">
                            <TextBlock 
                                Text="Fail Log Entries:"
                                Style="{StaticResource CaptionTextStyle}"/>
                            <StackPanel Orientation="Horizontal" Visibility="{Binding ShowAllLogEntriesPagingControls, Converter={StaticResource VisibilityConverter}}">
                            <Button>
                                <Image Source="{StaticResource IconVCRHome}" Stretch="None" /> 
                            </Button>
                            <Button>
                                <Image Source="{StaticResource IconVCRPrior}" Stretch="None" />
                            </Button>
                            <Button>
                                <Image Source="{StaticResource IconVCRNext}" Stretch="None" />
                            </Button>
                            <Button>
                                <Image Source="{StaticResource IconVCREnd}" Stretch="None" />
                            </Button>
                                </StackPanel>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                            <!--
                            <ToggleButton x:Name="FilterFail" Click="FilterLogEntries_Click" Tag="Fail" Margin="1,0,0,0" VerticalAlignment="Center" ToolTipService.ToolTip="Toggle filtering of failed test log entries" >
                                <Image Source="{Binding FilterFailed, Converter={StaticResource FilterIconConverter}, ConverterParameter=Fail}" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                            </ToggleButton>
                            <ToggleButton x:Name="FilterWarning" Click="FilterLogEntries_Click" Tag="Warning" Margin="1,0,0,0" VerticalAlignment="Center" ToolTipService.ToolTip="Toggle filtering of warning test log entries" >
                                <Image Source="{Binding FilterWarning, Converter={StaticResource FilterIconConverter}, ConverterParameter=Warning}" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                            </ToggleButton>
                            <ToggleButton x:Name="FilterPending" Click="FilterLogEntries_Click" Tag="Pending" Margin="1,0,0,0" VerticalAlignment="Center" ToolTipService.ToolTip="Toggle filtering of pending test log entries" >
                                <Image Source="{Binding FilterPending, Converter={StaticResource FilterIconConverter}, ConverterParameter=Pending}" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                            </ToggleButton>
                            <ToggleButton x:Name="FilterPass" Click="FilterLogEntries_Click" Tag="Pass" Margin="1,0,0,0" VerticalAlignment="Center" ToolTipService.ToolTip="Toggle filtering of passed test log entries" >
                                <Image Source="{Binding FilterPassed, Converter={StaticResource FilterIconConverter}, ConverterParameter=Pass}" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                            </ToggleButton> 
                            -->
                        </StackPanel>

                        <QuailControls:LogEntriesControl Grid.Row="1"
                                                         Grid.Column="0" 
                                                         Grid.ColumnSpan="2"
                                                         x:Name="AllLogEntries" />
                    </Grid>
                </Border>

                <Controls:GridSplitter Grid.Row="0" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Center" Width="5" 
                                       Visibility="{Binding ShowAllLogs, Converter={StaticResource VisibilityConverter}}"/>
                
                <Grid x:Name="GridTestResults" Grid.Row="0" Grid.Column="2" SizeChanged="OnGridTestResults_SizeChanged">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="25"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    
                    <Grid Grid.Row="0" Grid.Column="0">

                        <StackPanel HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
                            <Button Margin="0,0,0,0"
                                    Click="ShowLogs_Click"
                                    Width="25"
                                    ToolTipService.ToolTip="Show/Hide failed log entries">
                                <Image Source="{Binding ShowAllLogs, Converter={StaticResource ExpandLeftConverter}}"
                                       Stretch="None" />
                            </Button>
                            
                            <Button Visibility="{Binding ShowPopout, Converter={StaticResource VisibilityConverter}}"
                                    Margin="0,0,0,0"
                                    Click="Popout_Click"
                                    ToolTipService.ToolTip="View these results in a new window">
                                <Image Source="{StaticResource IconPopout}"
                                       Stretch="None" />
                            </Button>
                        </StackPanel>
                        <StackPanel HorizontalAlignment="Right" Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
                            <Button Margin="2,0,0,0"
                                    Click="ErrorPrior_Click"
                                    ToolTipService.ToolTip="Search for the prior unsuccessful task">
                                <Image Source="{StaticResource IconFailPrior}" Stretch="None" />
                            </Button>
                            <Button Margin="2,0,0,0"
                                    Click="ErrorNext_Click"
                                    ToolTipService.ToolTip="Search for the next unsuccessful task">
                                <Image Source="{StaticResource IconFailNext}" Stretch="None" />
                            </Button>

                            <TextBox Margin="5,0,0,0"
                                     x:Name="SearchBox"
                                     Width="100"
                                     KeyDown="SearchBox_KeyDown"
                                     ToolTipService.ToolTip="Enter a search term and press Enter" />
                            <Button Margin="5,0,0,0" Click="SearchBox_Click" ToolTipService.ToolTip="Click to search the tasks for the search term">
                                <Image Source="{StaticResource IconSearch}" Stretch="None" />
                            </Button>
                        </StackPanel>
                    </Grid>


                    <QuailControls:VirtualizingTreeView
                        x:Name="TreeViewTestResults"
                        ItemTemplate="{StaticResource myHierarchicalTemplate}"
                        SelectedItemChanged="TreeViewTestResults_SelectedItemChanged"
                        LayoutUpdated="TreeViewTestResults_LayoutUpdated"
                        VerticalAlignment="Top"
                        Grid.Row="1"
                        Grid.Column="0"
                        MinHeight="300"
                        Margin="0,5,0,0"
                        />
                </Grid>

                <Controls:GridSplitter Grid.Row="0" Grid.Column="3" VerticalAlignment="Stretch" HorizontalAlignment="Center" Width="5" />

                <Grid x:Name="RightGrid"
                      Grid.Row="0"
                      Grid.Column="4"
                      VerticalAlignment="Top"
                      HorizontalAlignment="Left">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="150"/>
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition MaxWidth="200"/>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Border
                        x:Name="SectionStatus" 
                        Grid.Row="0" 
                        Grid.Column="0" 
                        Style="{StaticResource DetailBorder}">
                        <StackPanel Orientation="Vertical" x:Name="TaskDetailGrid">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock VerticalAlignment="Center" Text="Status: " Style="{StaticResource CaptionTextStyle}" />
                                <TextBox Text="{Binding TaskStatus}" Style="{StaticResource TextBoxNoBorder}" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock VerticalAlignment="Center" Text="Name: " Style="{StaticResource CaptionTextStyle}"/>
                                <TextBox Text="{Binding TaskName}" Style="{StaticResource TextBoxNoBorder}" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock VerticalAlignment="Center" Text="Started: " Style="{StaticResource CaptionTextStyle}"/>
                                <TextBox Text="{Binding TaskStartDate}" Style="{StaticResource TextBoxNoBorder}" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock VerticalAlignment="Center" Text="Elapsed: " Style="{StaticResource CaptionTextStyle}"/>
                                <TextBox Text="{Binding Elapsed}" Style="{StaticResource TextBoxNoBorder}" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock VerticalAlignment="Center" Text="Duration: " Style="{StaticResource CaptionTextStyle}"/>
                                <TextBox Text="{Binding Duration}" Style="{StaticResource TextBoxNoBorder}" />
                            </StackPanel>
                        </StackPanel>
                    </Border>

                    <!-- panel for attributes -->
                    <Border
                                x:Name="SectionAttributes"
                                Grid.Row="0" 
                                Grid.Column="1"
                                Style="{StaticResource DetailBorder}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="20" />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Row="0" Grid.Column="0" Text="Attributes:" Style="{StaticResource CaptionTextStyle}"/>
                            <Grid Grid.Row="1" Grid.Column="0">
                                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                                    <c1grid:C1DataGrid
                                        IsReadOnly="True"
                                        AlternatingRowBackground="Beige" 
                                        AutoGenerateColumns="False" 
                                        RowHeight="Auto"
                                        x:Name="GridAttributes">
                                        <c1grid:C1DataGrid.Columns>
                                            <c1grid:DataGridTemplateColumn
                                                    Header="Name"
                                                    MinWidth="75">
                                                <c1grid:DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <TextBox Text="{Binding AttributeName}" />
                                                    </DataTemplate>
                                                </c1grid:DataGridTemplateColumn.CellTemplate>
                                            </c1grid:DataGridTemplateColumn>

                                            <c1grid:DataGridTemplateColumn
                                                    Header="Value"
                                                    MinWidth="225">
                                                <c1grid:DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <TextBox
                                                            TextWrapping="Wrap"
                                                            MaxWidth="750"
                                                            Text="{Binding AttributeValue}"
                                                            HorizontalScrollBarVisibility="Auto"
                                                            VerticalScrollBarVisibility="Auto"
                                                            MaxHeight="120"/>
                                                    </DataTemplate>

                                                </c1grid:DataGridTemplateColumn.CellTemplate>
                                            </c1grid:DataGridTemplateColumn>
                                        </c1grid:C1DataGrid.Columns>
                                    </c1grid:C1DataGrid>
                                </ScrollViewer>
                            </Grid>
                        </Grid>
                    </Border>

                    <!-- panel for lower section -->
                    <Border
                        x:Name="SectionLogs" 
                        Grid.Row="1"
                        Grid.Column="0"
                        Grid.ColumnSpan="2"
                        Style="{StaticResource DetailBorder}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="20" />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock 
                                Grid.Row="0"
                                Grid.Column="0"
                                    Text="Log Entries:"
                                    Style="{StaticResource CaptionTextStyle}"/>
                                <StackPanel Orientation="Horizontal" Visibility="{Binding ShowLogEntriesPagingControls, Converter={StaticResource VisibilityConverter}}">
                                    <Button Click="LogsHome_Click">
                                        <Image Source="{StaticResource IconVCRHome}" Stretch="None" />
                                    </Button>
                                    <Button Click="LogsPrior_Click">
                                        <Image Source="{StaticResource IconVCRPrior}" Stretch="None" />
                                    </Button>
                                    <Button Click="LogsNext_Click">
                                        <Image Source="{StaticResource IconVCRNext}" Stretch="None" />
                                    </Button>
                                    <Button Click="LogsEnd_Click">
                                        <Image Source="{StaticResource IconVCREnd}" Stretch="None" />
                                    </Button>
                                </StackPanel>
                            </StackPanel>

                            <QuailControls:LogEntriesControl Grid.Row="1" Grid.Column="0" x:Name="GridLogEntries" />
                        </Grid>
                    </Border>
                </Grid>
            </Grid>
        </ScrollViewer>
        <QuailControls:ProcessingModalControl x:Name="SearchModal" Text="Searching..."
                    ModalVisibility="{Binding IsSearching, Converter={StaticResource VisibilityConverter}}" />
        <QuailControls:ProcessingModalControl Text="{Binding ProcessingText}"
                    ModalVisibility="{Binding IsProcessing, Converter={StaticResource VisibilityConverter}}" />
    </Grid>
</UserControl>
